using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Diagnostics;

namespace ShareFileLANManagement
{
    public partial class MainFolder : DevComponents.DotNetBar.Office2007Form
    {
        public DriveInfo[] arrDrive = DriveInfo.GetDrives();
        public DirectoryInfo curDir_Left;
        public ArrayList arrItems_Left = new ArrayList();
        public MainFolder()
        {
            InitializeComponent();
        }

        private void OpenDirectory_Left(DirectoryInfo dr)
        {
            lstLeft.Items.Clear();
            arrItems_Left.Clear();
          
            // Duyet Thu Muc Trong dr
            foreach (DirectoryInfo subdir in dr.GetDirectories())
            {
                ListViewItem lvw = new ListViewItem();
                lvw.Text = subdir.Name;
                lvw.SubItems.Add("");
                lvw.SubItems.Add("Folder");
                lvw.ImageIndex = 1;

                // Add vao Listview va mang items
                lstLeft.Items.Add(lvw);
                arrItems_Left.Add(subdir);
                // Add Vao Bang ListView
                //lstLeft.Items.Add(lvw );


            }

            // Duyet Tat Ca Cac File Trong dr
            foreach (FileInfo file in dr.GetFiles())
            {
                ListViewItem lvw = new ListViewItem();
                
                string str1 = file.Name;
                string[] strSplit = str1.Split('.');
                string a = strSplit[0];
                string b = strSplit[1];
                lvw.Text = file.Name;
                if (b.Equals("rar"))
                {
                    lvw.ImageIndex = 2;

                }
                else
                {
                    lvw.ImageIndex = 0;
                }
                
                    lvw.Tag = file;
                    lvw.SubItems.Add(file.Length.ToString() + " Kb");
                    lvw.SubItems.Add("File");
                    
                    //lvw.ImageIndex = 0;
                    lstLeft.Items.Add(lvw);
                    arrItems_Left.Add(file);
               
            }


        }

        private void MainFolder_Load(object sender, EventArgs e)
        {
            curDir_Left = arrDrive[2].RootDirectory;
            OpenDirectory_Left(curDir_Left);
        }

        private void lstLeft_ItemActivate(object sender, EventArgs e)
        {
            // ////Viet Su Kien Double Click hay Enter Cho ComboBoxLeght
            int index = lstLeft.SelectedIndices[0];
            // Kiem Tra Thu Muc
            if (arrItems_Left[index].GetType() == typeof(DirectoryInfo))
            {
                curDir_Left = (DirectoryInfo)arrItems_Left[index];
                OpenDirectory_Left(curDir_Left);
            }
            //Kiem Tra Co phan tap tin

            else if (arrItems_Left[index].GetType() == typeof(FileInfo))
            {
                FileInfo file = (FileInfo)arrItems_Left[index];
                Process.Start(file.FullName);
            }
            
        }

        
    }
}